<template>
  <div class="user-management">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-content">
        <div class="header-left">
          <h1 class="page-title">用户管理</h1>
          <p class="page-subtitle">管理系统中的所有用户账户，共 {{ totalUsers }} 位用户</p>
        </div>
        <div class="header-right">
          <el-button type="primary" size="large" @click="showAddUserDialog" class="add-button">
            <el-icon><Plus /></el-icon>
            添加用户
          </el-button>
        </div>
      </div>
    </div>

    <!-- 搜索和筛选栏 -->
    <div class="search-bar">
      <div class="search-controls">
        <div class="search-input-wrapper">
          <el-input
            v-model="searchQuery"
            placeholder="搜索用户名或账号..."
            clearable
            class="search-input"
            @input="handleSearch"
            size="large"
          >
            <template #prefix>
              <el-icon><Search /></el-icon>
            </template>
          </el-input>
        </div>
        
        <el-select
          v-model="roleFilter"
          placeholder="筛选角色"
          clearable
          class="role-filter"
          @change="handleRoleFilter"
          size="large"
        >
          <el-option label="全部角色" value="" />
          <el-option label="管理员" value="admin" />
          <el-option label="普通用户" value="user" />
        </el-select>

        <el-select
          v-model="statusFilter"
          placeholder="筛选状态"
          clearable
          class="status-filter"
          @change="handleStatusFilter"
          size="large"
        >
          <el-option label="全部状态" value="" />
          <el-option label="正常" value="normal" />
          <el-option label="已禁用" value="ban" />
        </el-select>
      </div>
      
              <div class="search-stats">
        <span class="stats-text">显示 {{ users.length }} / {{ totalUsers }} 位用户</span>
      </div>
    </div>

    <!-- 用户表格 -->
    <div class="table-container">
      <el-table
        :data="users"
        v-loading="loading"
        class="user-table"
        :header-cell-style="{ background: '#fafbfc', color: '#374151', fontWeight: '600' }"
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        
        <el-table-column label="用户信息" min-width="200">
          <template #default="{ row }">
            <div class="user-info">
              <el-avatar :size="40" :src="ImageUtils.getImageUrl(row.userAvatar)">
                {{ row.userName?.charAt(0) || 'U' }}
              </el-avatar>
              <div class="user-details">
                <div class="user-name">{{ row.userName }}</div>
                <div class="user-account">@{{ row.userAccount }}</div>
              </div>
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="userEmail" label="邮箱" min-width="180">
          <template #default="{ row }">
            <span class="email-text">{{ row.userEmail || '未设置' }}</span>
          </template>
        </el-table-column>

        <el-table-column label="角色" width="120">
          <template #default="{ row }">
            <el-tag 
              :type="row.userRole === 'admin' ? 'danger' : (row.userRole === 'ban' ? 'info' : 'primary')"
              class="role-tag"
            >
              {{ row.userRole === 'admin' ? '管理员' : (row.userRole === 'ban' ? '已禁用' : '普通用户') }}
            </el-tag>
          </template>
        </el-table-column>

        <el-table-column label="状态" width="100">
          <template #default="{ row }">
            <el-tag 
              :type="getUserStatusType(row)"
              class="status-tag"
            >
              {{ getUserStatusText(row) }}
            </el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="createTime" label="注册时间" width="180">
          <template #default="{ row }">
            <div class="time-info">
              <div class="time-date">{{ formatDate(row.createTime) }}</div>
              <div class="time-relative">{{ getRelativeTime(row.createTime) }}</div>
            </div>
          </template>
        </el-table-column>

        <el-table-column label="操作" width="200" fixed="right">
          <template #default="{ row }">
            <div class="action-buttons">
              <el-tooltip content="编辑用户" placement="top">
                <el-button 
                  type="primary" 
                  size="small" 
                  circle
                  @click="editUser(row)"
                  :icon="Edit"
                />
              </el-tooltip>
              
              <el-tooltip :content="isUserBanned(row) ? '启用用户' : '禁用用户'" placement="top">
                <el-button 
                  :type="isUserBanned(row) ? 'success' : 'warning'"
                  size="small" 
                  circle
                  @click="toggleUserStatus(row)"
                  :icon="isUserBanned(row) ? Unlock : Lock"
                />
              </el-tooltip>
              
              <el-tooltip content="删除用户" placement="top">
                <el-button 
                  type="danger" 
                  size="small" 
                  circle
                  @click="deleteUser(row)"
                  :icon="Delete"
                />
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <!-- 批量操作栏 -->
      <div v-if="selectedUsers.length > 0" class="batch-actions">
        <div class="batch-info">
          已选择 {{ selectedUsers.length }} 位用户
        </div>
        <div class="batch-buttons">
          <el-button size="small" @click="batchEnable">批量启用</el-button>
          <el-button size="small" @click="batchDisable">批量禁用</el-button>
          <el-button type="danger" size="small" @click="batchDelete">批量删除</el-button>
        </div>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <el-pagination
          :current-page="currentPage"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="totalUsers"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
        />
      </div>
    </div>

    <!-- 添加/编辑用户对话框 -->
    <el-dialog
      v-model="dialogVisible"
      :title="dialogTitle"
      width="600px"
      class="user-dialog"
      @close="resetForm"
    >
      <el-form
        ref="userFormRef"
        :model="userForm"
        :rules="formRules"
        label-width="100px"
        class="user-form"
      >
        <div class="form-grid">
          <el-form-item label="用户名" prop="userName">
            <el-input 
              v-model="userForm.userName" 
              placeholder="请输入用户名"
              size="large"
            />
          </el-form-item>

          <el-form-item label="账号" prop="userAccount">
            <el-input 
              v-model="userForm.userAccount" 
              placeholder="请输入登录账号"
              :disabled="isEdit"
              size="large"
            />
          </el-form-item>

          <el-form-item label="邮箱" prop="userEmail">
            <el-input 
              v-model="userForm.userEmail" 
              placeholder="请输入邮箱地址"
              size="large"
            />
          </el-form-item>

          <el-form-item label="角色" prop="userRole">
            <el-select 
              v-model="userForm.userRole" 
              placeholder="请选择用户角色"
              size="large"
              style="width: 100%"
            >
              <el-option label="普通用户" value="user" />
              <el-option label="管理员" value="admin" />
            </el-select>
          </el-form-item>

          <el-form-item v-if="!isEdit" label="密码" prop="userPassword">
            <el-input 
              v-model="userForm.userPassword" 
              type="password" 
              placeholder="请输入登录密码"
              show-password
              size="large"
            />
          </el-form-item>

          <el-form-item v-if="!isEdit" label="确认密码" prop="confirmPassword">
            <el-input 
              v-model="userForm.confirmPassword" 
              type="password" 
              placeholder="请再次输入密码"
              show-password
              size="large"
            />
          </el-form-item>
        </div>

        <el-form-item label="个人简介" prop="userProfile">
          <el-input 
            v-model="userForm.userProfile" 
            type="textarea"
            :rows="3"
            placeholder="请输入个人简介（可选）"
            size="large"
          />
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogVisible = false" size="large">取消</el-button>
          <el-button type="primary" @click="submitForm" :loading="submitting" size="large">
            {{ isEdit ? '更新' : '创建' }}
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance } from 'element-plus'
import { 
  Search, 
  Plus, 
  Edit, 
  Delete, 
  Lock, 
  Unlock
} from '@element-plus/icons-vue'
import { ImageUtils } from '../../utils/imageUtils'
import { UserControllerService } from '../../services/UserControllerService'
import type { User } from '../../models/User'
import type { UserQueryRequest } from '../../models/UserQueryRequest'
import type { UserAddRequest } from '../../models/UserAddRequest'
import type { UserUpdateRequest } from '../../models/UserUpdateRequest'
import type { UserBanRequest } from '../../models/UserBanRequest'
import type { UserUnbanRequest } from '../../models/UserUnbanRequest'
import type { DeleteRequest } from '../../models/DeleteRequest'

// 响应式数据
const loading = ref(false)
const submitting = ref(false)
const dialogVisible = ref(false)
const isEdit = ref(false)
const searchQuery = ref('')
const roleFilter = ref('')
const statusFilter = ref('')
const currentPage = ref(1)
const pageSize = ref(10)
const selectedUsers = ref([])
const users = ref<User[]>([])
const total = ref(0)
const editingUserId = ref<number | null>(null)

// 表单
const userFormRef = ref<FormInstance>()
const userForm = reactive({
  userName: '',
  userAccount: '',
  userEmail: '',
  userPassword: '',
  confirmPassword: '',
  userRole: 'user',
  userProfile: ''
})

// 获取用户状态显示文本
const getUserStatusText = (user: User) => {
  if (user.userRole === 'ban') {
    return '已禁用'
  }
  return '正常'
}

// 获取用户状态类型
const getUserStatusType = (user: User) => {
  if (user.userRole === 'ban') {
    return 'danger'
  }
  return 'success'
}

// 判断用户是否被禁用
const isUserBanned = (user: User) => {
  return user.userRole === 'ban'
}

// 表单验证规则
const formRules = {
  userName: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 2, max: 20, message: '用户名长度为2-20个字符', trigger: 'blur' }
  ],
  userAccount: [
    { required: true, message: '请输入账号', trigger: 'blur' },
    { min: 3, max: 20, message: '账号长度为3-20个字符', trigger: 'blur' },
    { pattern: /^[a-zA-Z0-9_]+$/, message: '账号只能包含字母、数字和下划线', trigger: 'blur' }
  ],
  userEmail: [
    { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
  ],
  userPassword: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度为6-20个字符', trigger: 'blur' }
  ],
  confirmPassword: [
    { required: true, message: '请确认密码', trigger: 'blur' },
    {
      validator: (rule: any, value: string, callback: Function) => {
        if (value !== userForm.userPassword) {
          callback(new Error('两次输入密码不一致'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ],
  userRole: [
    { required: true, message: '请选择用户角色', trigger: 'change' }
  ]
}

// 计算属性
const totalUsers = computed(() => filteredUsers.value.length)

const filteredUsers = computed(() => {
  let result = users.value

  // 搜索过滤
  if (searchQuery.value) {
    const query = searchQuery.value.toLowerCase()
    result = result.filter(user => 
      user.userName.toLowerCase().includes(query) ||
      user.userAccount.toLowerCase().includes(query) ||
      (user.userEmail && user.userEmail.toLowerCase().includes(query))
    )
  }

  // 角色过滤
  if (roleFilter.value) {
    result = result.filter(user => user.userRole === roleFilter.value)
  }

  // 状态过滤
  if (statusFilter.value) {
    result = result.filter(user => user.status === statusFilter.value)
  }

  return result
})

const paginatedUsers = computed(() => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  return filteredUsers.value.slice(start, end)
})

const dialogTitle = computed(() => isEdit.value ? '编辑用户' : '添加用户')

// API调用方法
const loadUsers = async () => {
  try {
    loading.value = true
    
    // 构建查询参数
    const queryRequest: UserQueryRequest = {
      current: currentPage.value,
      pageSize: pageSize.value,
      userName: searchQuery.value || undefined
    }
    
    // 处理角色筛选
    if (roleFilter.value) {
      queryRequest.userRole = roleFilter.value
    }
    
    // 处理状态筛选 - 根据状态筛选设置角色
    if (statusFilter.value) {
      if (statusFilter.value === 'ban') {
        queryRequest.userRole = 'ban'
      } else if (statusFilter.value === 'normal') {
        // 正常状态包括admin和user，但排除ban
        // 这里我们先获取所有数据，然后在前端过滤
      }
    }
    
    const response = await UserControllerService.listUserByPage(queryRequest)
    if (response.code === 0 && response.data) {
      let userList = response.data.records || []
      
      // 前端过滤正常状态的用户
      if (statusFilter.value === 'normal') {
        userList = userList.filter(user => user.userRole !== 'ban')
      }
      
      users.value = userList
      total.value = response.data.total || 0
    } else {
      ElMessage.error(response.message || '获取用户列表失败')
    }
  } catch (error) {
    console.error('获取用户列表失败:', error)
    ElMessage.error('获取用户列表失败')
  } finally {
    loading.value = false
  }
}

// 方法
const handleSearch = () => {
  currentPage.value = 1
  loadUsers()
}

const handleRoleFilter = () => {
  currentPage.value = 1
  loadUsers()
}

const handleStatusFilter = () => {
  currentPage.value = 1
  loadUsers()
}

const handleSizeChange = (size: number) => {
  pageSize.value = size
  currentPage.value = 1
  loadUsers()
}

const handleCurrentChange = (page: number) => {
  currentPage.value = page
  loadUsers()
}

const handleSelectionChange = (selection: any[]) => {
  selectedUsers.value = selection
}

const showAddUserDialog = () => {
  isEdit.value = false
  dialogVisible.value = true
  resetForm()
}

const editUser = (user: any) => {
  isEdit.value = true
  dialogVisible.value = true
  editingUserId.value = user.id  // 保存被编辑用户的ID
  
  Object.assign(userForm, {
    userName: user.userName,
    userAccount: user.userAccount,
    userEmail: user.userEmail,
    userRole: user.userRole,
    userProfile: user.userProfile,
    userPassword: '',
    confirmPassword: ''
  })
}

const resetForm = () => {
  if (userFormRef.value) {
    userFormRef.value.resetFields()
  }
  Object.assign(userForm, {
    userName: '',
    userAccount: '',
    userEmail: '',
    userPassword: '',
    confirmPassword: '',
    userRole: 'user',
    userProfile: ''
  })
  editingUserId.value = null
}

const submitForm = async () => {
  if (!userFormRef.value) return
  
  try {
    await userFormRef.value.validate()
    submitting.value = true
    
    if (isEdit.value && editingUserId.value) {
      // 更新用户
      const updateRequest: UserUpdateRequest = {
        id: editingUserId.value,
        userName: userForm.userName,
        userProfile: userForm.userProfile,
        userRole: userForm.userRole
      }
      
      const response = await UserControllerService.updateUser(updateRequest)
      if (response.code === 0) {
        ElMessage.success('用户信息更新成功')
        await loadUsers()
      } else {
        ElMessage.error(response.message || '更新失败')
      }
    } else {
      // 添加新用户
      const addRequest: UserAddRequest = {
        userName: userForm.userName,
        userAccount: userForm.userAccount,
        userRole: userForm.userRole
      }
      
      const response = await UserControllerService.addUser(addRequest)
      if (response.code === 0) {
        ElMessage.success('用户创建成功')
        await loadUsers()
      } else {
        ElMessage.error(response.message || '创建失败')
      }
    }
    
    dialogVisible.value = false
    resetForm()
  } catch (error) {
    console.error('表单提交失败:', error)
    ElMessage.error('操作失败')
  } finally {
    submitting.value = false
  }
}

const toggleUserStatus = async (user: User) => {
  if (!user.id) return
  
  const isBanned = isUserBanned(user)
  const action = isBanned ? '启用' : '禁用'
  
  try {
    await ElMessageBox.confirm(`确定要${action}用户 "${user.userName}" 吗？`, '确认操作', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    if (isBanned) {
      // 启用用户
      const unbanRequest: UserUnbanRequest = {
        id: user.id
      }
      const response = await UserControllerService.unbanUser(unbanRequest)
      if (response.code === 0) {
        ElMessage.success('用户启用成功')
        await loadUsers()
      } else {
        ElMessage.error(response.message || '启用失败')
      }
    } else {
      // 禁用用户
      const banRequest: UserBanRequest = {
        id: user.id,
        banReason: '管理员手动禁用'
      }
      const response = await UserControllerService.banUser(banRequest)
      if (response.code === 0) {
        ElMessage.success('用户禁用成功')
        await loadUsers()
      } else {
        ElMessage.error(response.message || '禁用失败')
      }
    }
  } catch (error) {
    if (error !== 'cancel') {
      console.error(`用户${action}失败:`, error)
      ElMessage.error(`用户${action}失败`)
    }
  }
}

const deleteUser = async (user: User) => {
  if (!user.id) return
  
  try {
    await ElMessageBox.confirm(`确定要删除用户 "${user.userName}" 吗？此操作不可恢复！`, '确认删除', {
      confirmButtonText: '确定删除',
      cancelButtonText: '取消',
      type: 'error'
    })
    
    const deleteRequest: DeleteRequest = {
      id: user.id
    }
    
    const response = await UserControllerService.deleteUser(deleteRequest)
    if (response.code === 0) {
      ElMessage.success('用户删除成功')
      await loadUsers()
    } else {
      ElMessage.error(response.message || '删除失败')
    }
  } catch (error) {
    if (error !== 'cancel') {
      console.error('删除用户失败:', error)
      ElMessage.error('删除用户失败')
    }
  }
}

const batchEnable = async () => {
  if (selectedUsers.value.length === 0) return
  
  try {
    await ElMessageBox.confirm(`确定要启用选中的 ${selectedUsers.value.length} 位用户吗？`, '确认操作', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    const promises = selectedUsers.value
      .filter((user: User) => isUserBanned(user) && user.id)
      .map((user: User) => {
        const unbanRequest: UserUnbanRequest = { id: user.id! }
        return UserControllerService.unbanUser(unbanRequest)
      })
    
    await Promise.all(promises)
    ElMessage.success('批量启用成功')
    selectedUsers.value = []
    await loadUsers()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('批量启用失败:', error)
      ElMessage.error('批量启用失败')
    }
  }
}

const batchDisable = async () => {
  if (selectedUsers.value.length === 0) return
  
  try {
    await ElMessageBox.confirm(`确定要禁用选中的 ${selectedUsers.value.length} 位用户吗？`, '确认操作', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    
    const promises = selectedUsers.value
      .filter((user: User) => !isUserBanned(user) && user.id)
      .map((user: User) => {
        const banRequest: UserBanRequest = { 
          id: user.id!,
          banReason: '批量禁用'
        }
        return UserControllerService.banUser(banRequest)
      })
    
    await Promise.all(promises)
    ElMessage.success('批量禁用成功')
    selectedUsers.value = []
    await loadUsers()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('批量禁用失败:', error)
      ElMessage.error('批量禁用失败')
    }
  }
}

const batchDelete = async () => {
  if (selectedUsers.value.length === 0) return
  
  try {
    await ElMessageBox.confirm(
      `确定要删除选中的 ${selectedUsers.value.length} 位用户吗？此操作不可恢复！`, 
      '确认删除', 
      {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消',
        type: 'error'
      }
    )
    
    const promises = selectedUsers.value
      .filter((user: User) => user.id)
      .map((user: User) => {
        const deleteRequest: DeleteRequest = { id: user.id! }
        return UserControllerService.deleteUser(deleteRequest)
      })
    
    await Promise.all(promises)
    ElMessage.success('批量删除成功')
    selectedUsers.value = []
    await loadUsers()
  } catch (error) {
    if (error !== 'cancel') {
      console.error('批量删除失败:', error)
      ElMessage.error('批量删除失败')
    }
  }
}

const formatDate = (dateString: string) => {
  return new Date(dateString).toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  })
}

const getRelativeTime = (dateString: string) => {
  const now = new Date()
  const date = new Date(dateString)
  const diff = now.getTime() - date.getTime()
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  
  if (days === 0) return '今天'
  if (days === 1) return '昨天'
  if (days < 7) return `${days}天前`
  if (days < 30) return `${Math.floor(days / 7)}周前`
  if (days < 365) return `${Math.floor(days / 30)}月前`
  return `${Math.floor(days / 365)}年前`
}

// 生命周期
onMounted(() => {
  console.log('用户管理页面加载完成')
  loadUsers()
})
</script>

<style scoped>
.user-management {
  min-height: 100vh;
  background: transparent;
}

/* 页面头部 */
.page-header {
  margin-bottom: 24px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 16px;
  color: #1f2937;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 8px 0;
  color: #1f2937;
}

.page-subtitle {
  margin: 0;
  font-size: 16px;
  color: #6b7280;
  line-height: 1.6;
}

.add-button {
  background: #3b82f6;
  border: 1px solid #3b82f6;
  color: white;
  font-weight: 600;
}

.add-button:hover {
  background: #2563eb;
  border-color: #2563eb;
}

/* 搜索栏 */
.search-bar {
  background: white;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.search-controls {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.search-input-wrapper {
  flex: 1;
  max-width: 400px;
}

.search-input {
  border-radius: 12px;
}

.role-filter,
.status-filter {
  min-width: 150px;
}

.search-stats {
  padding-top: 16px;
  border-top: 1px solid #f3f4f6;
}

.stats-text {
  color: #6b7280;
  font-size: 14px;
  font-weight: 500;
}

/* 表格容器 */
.table-container {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.user-table {
  border-radius: 12px;
  overflow: hidden;
}

:deep(.user-table .el-table__header-wrapper) {
  border-radius: 12px 12px 0 0;
}

:deep(.user-table .el-table__row) {
  transition: all 0.3s ease;
}

:deep(.user-table .el-table__row:hover) {
  background-color: #f8fafc;
}

/* 用户信息 */
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 2px;
}

.user-account {
  font-size: 13px;
  color: #6b7280;
}

.email-text {
  color: #4b5563;
  font-size: 14px;
}

/* 标签 */
.role-tag,
.status-tag {
  font-weight: 600;
  border-radius: 8px;
  padding: 4px 12px;
}

/* 时间信息 */
.time-info {
  text-align: left;
}

.time-date {
  font-size: 14px;
  color: #374151;
  margin-bottom: 2px;
}

.time-relative {
  font-size: 12px;
  color: #9ca3af;
}

/* 操作按钮 */
.action-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* 批量操作 */
.batch-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding: 16px;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.batch-info {
  font-size: 14px;
  color: #475569;
  font-weight: 500;
}

.batch-buttons {
  display: flex;
  gap: 8px;
}

/* 分页 */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #f3f4f6;
}

/* 对话框 */
:deep(.user-dialog .el-dialog__header) {
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  color: #1f2937;
  margin: 0;
  padding: 20px 24px;
  border-radius: 16px 16px 0 0;
  border-bottom: 1px solid #e5e7eb;
}

:deep(.user-dialog .el-dialog__title) {
  color: #1f2937;
  font-weight: 600;
  font-size: 18px;
}

:deep(.user-dialog .el-dialog__headerbtn .el-dialog__close) {
  color: #6b7280;
}

:deep(.user-dialog .el-dialog__body) {
  padding: 24px;
}

.user-form {
  padding: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 16px;
}

:deep(.form-grid .el-form-item:nth-child(5)),
:deep(.form-grid .el-form-item:nth-child(6)) {
  grid-column: 1 / -1;
}

:deep(.user-form .el-form-item__label) {
  font-weight: 600;
  color: #374151;
}

:deep(.user-form .el-input__wrapper) {
  border-radius: 8px;
}

:deep(.user-form .el-select .el-input__wrapper) {
  border-radius: 8px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  background: #f8fafc;
  margin: 0 -24px -24px -24px;
  border-radius: 0 0 16px 16px;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .search-controls {
    flex-wrap: wrap;
  }
  
  .search-input-wrapper {
    flex: 1 1 300px;
  }
  
  .role-filter,
  .status-filter {
    flex: 1 1 120px;
  }
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }
  
  .page-title {
    font-size: 28px;
  }
  
  .search-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .search-input-wrapper {
    max-width: none;
  }
  
  .table-container {
    padding: 16px;
  }
  
  .batch-actions {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  :deep(.form-grid .el-form-item:nth-child(5)),
  :deep(.form-grid .el-form-item:nth-child(6)) {
    grid-column: 1;
  }
}

/* 滚动条样式 */
.table-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.table-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.table-container::-webkit-scrollbar-track {
  background: transparent;
}
</style>